package com.jsz.peini.common.util;

import java.util.ArrayList;
import java.util.List;

import com.jsz.peini.bean.codes.SystemCode;

/**
 * param code:字典表码值
 *
 */
public class GetCode {
	
	private List<SystemCode> allList;
	
	public GetCode(){
		Object codeObject = EhcacheUtil.getInstance().get("codeCache", "codeList");
		allList = (List<SystemCode>)codeObject;
	}
	
	//获取字典表对应字典码所有值
	public List<SystemCode> getCodeList(int code){
		List<SystemCode> codeList = new ArrayList();
		for(SystemCode systemCode: allList){
			if(systemCode.getCodes()==code){
				codeList.add(systemCode);
			}
		}
		return codeList;
	}
	
	//获取字典表对应字典对象
	public SystemCode getCodeBean(int code,int codeNum){
		SystemCode sc = new SystemCode();
		for(SystemCode systemCode: allList){
			if(systemCode.getCodes()==code&&systemCode.getCodesNum()==codeNum){
				sc = systemCode;
				break;
			}
		}
		return sc;
	}
	
	//获取字典表对应对象名称
	public String getCodeName(int code,int codeNum){
		SystemCode sc = new SystemCode();
		for(SystemCode systemCode: allList){
			if(systemCode.getCodes()==code&&systemCode.getCodesNum()==codeNum){
				sc = systemCode;
				break;
			}
		}
		return sc.getCodesName();
	}
	
	

}
